package com.shenzhen.horselive.ui.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.shenzhen.horselive.R;
import com.shenzhen.horselive.User;
import com.shenzhen.horselive.api.ApiFactory;
import com.shenzhen.horselive.base.AppBarActivity;
import com.shenzhen.horselive.beans.CommResponseBean;
import com.shenzhen.horselive.databinding.ActivityMyAliPayBinding;
import com.shenzhen.horselive.network.SchedulersCompat;
import com.shenzhen.horselive.presenter.LoadingViewObserver;

public class MyAliPayActivity extends AppBarActivity {

    ActivityMyAliPayBinding  binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding =  ActivityMyAliPayBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        setStyleDark();
        setTitle("我的支付宝");
        initViews();


    }

    private void initViews() {
        binding.btGo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                submit();
            }
        });


    }

    private void submit() {
        String name = binding.etName.getText().toString();
        if (TextUtils.isEmpty(name))
        {
           return;
        }
        String zhanghao = binding.etZhanghao.getText().toString();
        if (TextUtils.isEmpty(zhanghao))
        {
            return;
        }
        //提交
        ApiFactory.getApiService().setAliPay(User.get().getMyInfo().getToken()
        ,name,zhanghao).compose(SchedulersCompat.applyIoSchedulers())
                .safeSubscribe(new LoadingViewObserver<CommResponseBean>(this) {
                    @Override
                    protected void onNextInActive(CommResponseBean commResponseBean) {
                         if (commResponseBean.isSuccess())
                         {
                             showToast("设置成功");
                             setResult(1001);
                             finish();
                         }
                         else{
                             showToast(commResponseBean.getErrMessage());
                         }
                    }
                });

    }
}